from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


# 用户表
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    account = db.Column(db.String(48), nullable=False, unique=True)
    password = db.Column(db.String(124), nullable=False)
    name = db.Column(db.String(124), nullable=False)
    head_img = db.Column(db.String(255))
    MD5PWD = db.Column(db.String(200), nullable=False)
    token = db.Column(db.String(200), nullable=False)
    guid = db.Column(db.String(200), nullable=False, unique=True)

    def __init__(self):
        self.name = None
        self.account = None
        self.password = None
        self.token = None
        self.guid = None
        self.MD5PWD = None


# 图书的分类
class BookClassify(db.Model):
    __tablename__ = 'BookClassify'
    id = db.Column(db.Integer, primary_key=True)
    classifyName = db.Column(db.String(20), nullable=False, unique=True)


# 图书
class Book(db.Model):
    __tablename__ = 'Book'
    title = db.Column(db.String(200), nullable=False)
    author = db.Column(db.String(200), nullable=False)
    synopsis = db.Column(db.String(200), nullable=False)
    img = db.Column(db.String(300))
    classifyID = db.Column(db.Integer, db.ForeignKey('BookClassify.id'))
    chapterCount = db.Column(db.String(80), nullable=True)
    bookGuid = db.Column(db.String(200), nullable=False,primary_key=True)
